final static int NORTH = 1;
final static int EAST = 2;
final static int SOUTH = 4;
final static int WEST = 8;
PImage img,img1,img2,img3;
int result;
float x,y;
 
void setup() {
  background(255);
  size(512,400);
  frameRate(30);  
  result=0;
  x=width/2;
  y=height/2;
  img=loadImage("let.jpg");
  img1=loadImage("let1.jpg");
  img2=loadImage("let2.jpg");
  img3=loadImage("let3.jpg");
} 
void draw() {
 if(keyPressed==true)
   background(255);
  switch(result){
    case NORTH:y--;image(img2,x,y);break;
    case EAST:x++;image(img1,x,y);break;
    case SOUTH:y++;image(img3,x,y);break;
    case WEST:x--;image(img,x,y);break;
    case NORTH|EAST:y--;x++;image(img1,x,y);break;
    case NORTH|WEST:y--;x--;image(img,x,y);break;
    case SOUTH|EAST:y++;x++;image(img1,x,y);break;
    case SOUTH|WEST:y++;x--;image(img,x,y);break;
  }
} 
void keyPressed(){
  switch(key) {
    case('w'):case('W'):result |=NORTH;break;
    case('d'):case('D'):result |=EAST;break;
    case('s'):case('S'):result |=SOUTH;break;
    case('a'):case('A'):result |=WEST;break;
  }
} 
void keyReleased(){  
  switch(key) {
    case('w'):case('W'):result ^=NORTH;break;
    case('d'):case('D'):result ^=EAST;break;
    case('s'):case('S'):result ^=SOUTH;break;
    case('a'):case('A'):result ^=WEST;break;
  }
}
